package kuzmenkov.oip.common;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
import java.util.logging.Logger;

/**
 * Class finds beans. NOT USED!!//todo
 * User: Michael Kuzmenkov
 * Date: 15.03.2009
 * Time: 22:25:13
 */
public class ServiceFinder {
    private static Logger log = Logger.getLogger("global");

    private ServiceFinder(){}

    public static Object findBean(String beanName) {//todo

        FacesContext context = FacesContext.getCurrentInstance();
        //log.info("FacesContext:"+context);

        ServletContext servletContext =
                (ServletContext) context.getExternalContext().getContext();
        //log.info("ServletContext"+servletContext);

        ApplicationContext appContext =
                WebApplicationContextUtils.getWebApplicationContext(servletContext);
        //log.info("ApplicationContext:"+appContext);

        return appContext.getBean(beanName);
    }

    private static Object findManagedBean(String sBeanName) {//todo
        return FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get(sBeanName);
    }

}
